This assignment aims to compare the performance of various image smoothing filters applied to noisy images. The filters under consideration include simple smoothing filters such as Box filter, Gaussian filter, and Median filter, as well as advanced filters like Bilateral filter and Adaptive Median filter. The evaluation will focus on noise removal effectiveness, edge preservation, computational efficiency, and the influence of kernel size on the performance of each filter. Quantitative metrics such as Mean Squared Error (MSE) and Peak Signal-to-Noise Ratio (PSNR) will be used for comparison.
Box Filter:
Median Filter:
Gaussian Filter:
Bilateral Filter:
Adaptive Median Filter:
Adaptive Mean Filter:
The comparison of these filters will provide insights into their strengths and weaknesses in different aspects of image processing, highlighting their suitability for various applications.
import cv2
import matplotlib.pyplot as plt
import utilities as utils
import os
import metrics
import filters
import visualization as vis
from sklearn.metrics import mean_squared_error
The images used in this analysis are categorized based on the level of detail they contain. The categories are as follows:
Low Details:
Medium Details:
High Details:
The images are processed and analyzed to compare the performance of various filters, including Box filter, Gaussian filter, Median filter, Bilateral filter, Adaptive Median filter, and Canny edge detector. The evaluation focuses on noise removal effectiveness, edge preservation, computational efficiency, and the influence of kernel size on the performance of each filter.
The cell below shows the images to be worked on for this assignment.
list_of_images = []
PATH = 'images'
images_dir = os.listdir(PATH)
images_dir.sort()
# Iterate over images
for images in images_dir:
image = cv2.imread(os.path.join(PATH, images), cv2.IMREAD_GRAYSCALE)
list_of_images.append(image)
titles = ["Low details", "Medium details", "High details"]
vis.plot_images(list_of_images, titles)
In this section, we will discuss the process of generating noise and applying it to images. Noise is an unwanted random variation in the pixel values of an image, which can degrade the visual quality and affect the performance of image processing algorithms. Different types of noise can be introduced to simulate real-world scenarios and evaluate the robustness of image processing techniques.
Gaussian Noise:
Salt and Pepper Noise:
To evaluate the performance of various image smoothing filters, we apply different types of noise to the original images. This allows us to test the effectiveness of the filters in removing noise while preserving important image details such as edges and textures.
The following steps are involved in applying noise to images:
Load the Original Image:
Generate Noise:
The cell below calls a function that creates a pandas dataframe for each image. This dataframe indices has the noise variations of the image, including the original image.
For instance, df['Gaussian Noise (medium)'] fetches the image corrupted with medium gaussian noise.
dataframes = {}
for i, image in enumerate(list_of_images):
df = utils.create_dataframe_image(image)
details = titles[i]
dataframes[details] = df
The cell below shows each of noises with different levels of intensities, applied on all of the images.
# Define the noise types to display
noise_types = ['Gaussian Noise', 'Salt and Pepper Noise']
intensities = ['low', 'medium','high']
for df_dict in dataframes.items():
df = df_dict[1]
vis.plot_original_noisy_images(df, noise_types, intensities, df_dict[0])
print("\n" + "="*80 + "\n")
================================================================================